package com.iflytek.util;


import org.apache.commons.dbcp.BasicDataSource;
import org.omg.CORBA.BAD_CONTEXT;

import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;

public class Dbutils {
    /*
     *根据db.properties文件构造DataSource对象并返回
     */
    public static DataSource getDataSource() {
        BasicDataSource basicDataSource = new BasicDataSource();
        Properties properties = new Properties();
        try {
            properties.load(Dbutils.class.getClassLoader().getResourceAsStream("db.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        basicDataSource.setDriverClassName(properties.getProperty("driver"));
        basicDataSource.setUrl(properties.getProperty("url"));
        basicDataSource.setUsername(properties.getProperty("username"));
        basicDataSource.setPassword(properties.getProperty("password"));
        return basicDataSource;

    }
}

